export function dateFormat(date?: Date, format: string = 'yyyy-mm-dd') {
    if (!date) {
        return '';
    }
    const time = new Date(date);
    const year = time.getFullYear();
    const month = String(time.getMonth() + 1).padStart(2, '0');
    const day = String(time.getDate()).padStart(2, '0');
    let hour: any = time.getHours();
    let minute: any = time.getMinutes();
    let second: any = time.getMinutes();

    hour = hour < 10 ? '0' + hour : hour;
    minute = minute < 10 ? '0' + minute : minute;
    second = second < 10 ? '0' + second : second;

    if (format.toLowerCase() === "yyyy-mm-dd") {
        return `${year}-${month}-${day}`;
    } else {
        return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
    }
}

export function timeFormat(date?: Date) {
    if (!date) {
        return '';
    }
    const time = new Date(date);
    let hour: any = time.getHours();
    let minute: any = time.getMinutes();
    let second: any = time.getMinutes();

    hour = hour < 10 ? '0' + hour : hour;
    minute = minute < 10 ? '0' + minute : minute;
    second = second < 10 ? '0' + second : second;

    return hour + ':' + minute + ':' + second;

}
